<?php

class DefaultController extends Controller
{
	public function filters()
	{
		return array(
			array(
				'CHttpCacheFilter + index',
				'lastModified'=>time() + 3600,
			),
			array(
				'COutputCache',
				'duration' => 3600,
				'varyByRoute' => true,
				'varyByParam' => array('id'),
			),
		);
	}

	public function actionIndex($id)
	{
		$toView = array();
		$oPages = new Pages();
		$oCategories = new Categories();

		$toView['oRow'] = $oRow = $oPages->findByAttributes(array('alias' => $id));

		if(empty($toView['oRow']))
			throw new CHttpException(404,'Page not found');

//		var_dump(Yii::app()->request->isAjaxRequest);
		if(Yii::app()->request->isAjaxRequest)
		{
			$this->layout = '//layouts/empty';
			return $this->render('index', $toView);
		}

		if($oRow->category_id > 0)
		{
			$oCategory = $oCategories->id($oRow->category_id)->find();
			$this->breadcrumbs[$oCategory->title] = 'javascript: return void(0);';
		}

		$this->breadcrumbs[$oRow->title] = Yii::app()->createUrl('pages/default/index', array('id' => $oRow->createUrlId()));

		$title = $oRow->title . '.';
		$description = String::substr(String::stripTagsAttributes($oRow->description), 160) .'. Интернет магазин '. Yii::app()->name. '';
		$this->addTitle($title)
			->addKeywords('Обувь, одежда, сумки, аксессуары, америка, usa')
			->addDescription($description);

		$this->render('index', $toView);
	}
}